package com.xc.erp.modules.erp.controller.systemConfig;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xc.erp.common.annotation.Log;
import com.xc.erp.common.utils.SecurityUtils;
import com.xc.erp.modules.erp.domain.AjaxResult;
import com.xc.erp.modules.erp.domain.pojo.JshSystemConfig;
import com.xc.erp.modules.erp.service.JshSystemConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("系统配置")
@RestController
@RequestMapping("/systemConfig")
public class SystemConfigController {

    @Autowired
    private JshSystemConfigService jshSystemConfigService;

    @ApiOperation("查询配置列表")
    @GetMapping("/list/{pageSize}/{pageNum}")
    public AjaxResult list(@PathVariable Integer pageSize, @PathVariable Integer pageNum, String companyName) {
        Page<JshSystemConfig> list = jshSystemConfigService.list(pageSize, pageNum, companyName);
        return AjaxResult.success(list);
    }

    @Log(modul = "系统配置",desc = "新增")
    @ApiOperation("新增")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JshSystemConfig jshSystemConfig) {
        jshSystemConfig.setTenantId(SecurityUtils.getLoginUser().getJshUser().getTenantId());
        jshSystemConfigService.save(jshSystemConfig);
        return AjaxResult.success();
    }

    @Log(modul = "系统配置",desc = "修改")
    @ApiOperation("修改")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody JshSystemConfig jshSystemConfig) {
        jshSystemConfigService.updateById(jshSystemConfig);
        return AjaxResult.success();
    }

    @Log(modul = "系统配置",desc = "删除")
    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Long id){
        jshSystemConfigService.removeById(id);
        return AjaxResult.success();
    }

    @ApiOperation("检查名称是否存在")
    @GetMapping("/checkIsNameExist")
    public AjaxResult checkIsNameExist(Long id,String companyName){
        boolean status = jshSystemConfigService.checkIsNameExist(id,companyName);
        return AjaxResult.success().put("status",status);
    }
}
